home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 June / EnigmA AMIGA RUN 08 (1996)(G.R. Edizioni)(IT)[!][issue 1996-06][EARSAN CD VII].iso / earcd / comm1 / qwesorcs.lha / qwe_sources / cdnet / CDNet.c next >
Text File  |  1995-12-16  |  7KB  |  487 lines

  1. const char *_VERSION="\0$VER: CDNet 1.2 (27.08.95)";
  2.  
  3. #include <cnet/empty.h>
  4. #include <dos/dos.h>
  5.  
  6. FILE    *fp;
  7.  
  8. char    key[3],
  9.         indexpfad[81]="pfiles:cdnet/",
  10.         treepfad[81]="pfiles:cdnet/",
  11.         ansipfad1[25]="pfiles:cdnet/cdnet.ansi1",
  12.         ansipfad2[25]="pfiles:cdnet/cdnet.ansi2",
  13.         readmepfad[81],
  14.         filepfad[81],
  15.  
  16.         pfad[15],
  17.  
  18.         line_a[150],
  19.         line_b[150],
  20.  
  21.         tree[300][80];
  22.  
  23. UBYTE    anz_tree,
  24.         pos=1,
  25.         merkpos,
  26.         zeilen,
  27.         merkzeilen;
  28.  
  29. BOOL    files=FALSE,
  30.         more;
  31.  
  32. int        zeiger,filenummer;
  33.  
  34. UBYTE    x,y,i,j,k;
  35.  
  36. char    *speicher,*p,*p2,*p3,*pp[2000];
  37.  
  38. ULONG    laenge,bytes;
  39.  
  40. short    merkanzahl;
  41.  
  42. byte    moremode;
  43.  
  44. struct FileLock *lock;
  45. struct FileInfoBlock *fib_ptr;    /* Declare a FileInfoBlock */
  46.                                 /* pointer called fib_ptr. */
  47.  
  48. void blank(UBYTE t_pos)
  49. {
  50.     sprintf(line_b,"%d;1H ",t_pos+4);
  51.     PutText(line_b);
  52. }
  53. void cursor(UBYTE t_pos)
  54. {
  55.     sprintf(line_b,"%d;1H>D",t_pos+4);
  56.     PutText(line_b);
  57. }
  58.  
  59. void copyindex(UBYTE letzte_zeile)
  60. {
  61.     if(*p=='#' || *p==0)
  62.     {
  63.         more=FALSE;
  64.         return;
  65.     }
  66.  
  67.     j=0;
  68.     while(*p!=10)
  69.     {
  70.         line_a[j++]=*p++;
  71.     }
  72.     line_a[j]=10;
  73.     line_a[j+1-letzte_zeile]=0;
  74.     p++;
  75. }
  76.  
  77. void rauf(void)
  78. {
  79.     if(pos>1)
  80.     {
  81.         blank(pos);
  82.         pos--;
  83.         cursor(pos);
  84.     }
  85.     else
  86.     {
  87.         if(files)
  88.         {
  89.             if(filenummer>zeilen+1)
  90.             {
  91.                 more=TRUE;
  92.                 filenummer--;
  93.                 p=pp[filenummer-zeilen-1];
  94.                 copyindex(1);
  95.                 blank(pos);
  96.                 sprintf(line_b,"HL%d;1H",pos+4);
  97.                 PutText(line_b);
  98.                 PutText(line_a);
  99.                 cursor(pos);
  100.             }
  101.         }
  102.         else
  103.         {
  104.             if(zeiger>0)
  105.             {
  106.                 blank(pos);
  107.                 zeiger--;
  108.                 sprintf(line_a,"HL%s",tree[zeiger]);
  109.                 PutText(line_a);
  110.                 cursor(pos);
  111.             }
  112.         }
  113.     }
  114. }
  115.  
  116. void runter(void)
  117. {
  118.     if(pos<zeilen)
  119.     {
  120.         p=pp[filenummer-zeilen+pos];
  121.         blank(pos);
  122.         pos++;
  123.         cursor(pos);
  124.     }
  125.     else
  126.     {
  127.         if(files)
  128.         {
  129.             if(more)
  130.             {
  131.                 if(more)
  132.                 {
  133.                     copyindex(1);
  134.                     if(more)
  135.                     {
  136.                         pp[filenummer++]=p;
  137.                         blank(pos);
  138.                         sprintf(line_b,"HM%d;1H",pos+4);
  139.                         PutText(line_b);
  140.                         PutText(line_a);
  141.                         cursor(pos);
  142.                     }
  143.                 }
  144.             }
  145.         }
  146.         else
  147.         {
  148.             if(zeiger+pos-1<anz_tree)
  149.             {
  150.                 blank(pos);
  151.                 zeiger++;
  152.                 sprintf(line_a,"HM%d;1H",pos+4);
  153.                 PutText(line_a);
  154.                 PutText(tree[zeiger+pos-1]);
  155.                 cursor(pos);
  156.             }
  157.         }
  158.     }
  159. }
  160.  
  161. void info(void)
  162. {
  163.     strcpy(line_b,readmepfad);
  164.     AddPart(line_b,pfad,80);
  165.  
  166.     p2=line_a;
  167.     p3=pp[filenummer-zeilen-2+pos];
  168.     p3++;
  169.     while(*p3!=32)
  170.     {
  171.         *p2++=*p3++;
  172.     }
  173.     strcpy((p2-3),"readme\0");
  174.  
  175.     AddPart(line_b,line_a,80);
  176.     z->user1.MoreMode=1;
  177.     PutText("F1");
  178.     ReadFile(line_b,0);
  179.     PutText("C7Press RETURN to continueG0");
  180.     z->user1.MoreMode=0;
  181.     ReadFile(ansipfad2,0);
  182.     sprintf(line_a,"3H%d 1H%d   H",z->NoSelected,bytes/1000);
  183.     PutText(line_a);
  184.     p=pp[filenummer-zeilen-1];
  185.     for(i=filenummer-zeilen-1;i<filenummer-2;i++)
  186.     {
  187.         copyindex(0);
  188.         PutText(line_a);
  189.     }
  190.     copyindex(1);
  191.     PutText(line_a);
  192.     cursor(pos);
  193. }
  194.  
  195. void dirs(void)
  196. {
  197.     i=0;
  198.  
  199.     if(files)
  200.     {
  201.         ReadFile(ansipfad2,0);
  202.         sprintf(line_a,"3H%d 1H%d   H",z->NoSelected,bytes/1000);
  203.         PutText(line_a);
  204.         more=TRUE;
  205.         while(i<zeilen-1 && more)
  206.         {
  207.             copyindex(0);
  208.             if(more)
  209.             {
  210.                 pp[filenummer++]=p;
  211.                 PutText(line_a);
  212.                 i++;
  213.             }
  214.         }
  215.         if(more)
  216.         {
  217.             copyindex(1);
  218.             if(more)
  219.             {
  220.                 pp[filenummer++]=p;
  221.                 PutText(line_a);
  222.             }
  223.         }
  224.         merkzeilen=zeilen;
  225.         zeilen=filenummer-1;
  226.     }
  227.     else
  228.     {
  229.         ReadFile(ansipfad1,0);
  230.         sprintf(line_a,"3H%d 1H%d   H",z->NoSelected,bytes/1000);
  231.         PutText(line_a);
  232.         while(i<zeilen-1)
  233.         {
  234.             sprintf(line_a,"%s\n",tree[i+zeiger]);
  235.             PutText(line_a);
  236.             i++;
  237.         }
  238.         sprintf(line_a,"%s",tree[i+zeiger]);
  239.         PutText(line_a);
  240.     }
  241.     cursor(pos);
  242. }
  243.  
  244. void go_files(void)
  245. {
  246.     j=1;
  247.     while(tree[zeiger+pos-1][j]!=' ') /* suchstring erstellen */
  248.     {
  249.         line_a[j]=tree[zeiger+pos-1][j];
  250.         j++;
  251.     }
  252.     line_a[j]=0;
  253.     line_a[0]='#';
  254.  
  255.     strcpy(pfad,line_a+1);
  256.  
  257.     if(p=strstr(speicher,line_a))
  258.     {
  259.         while(*p!=10) /* naechste zeile suchen */
  260.         {
  261.             p++;
  262.         }
  263.         p++;
  264.  
  265.         merkpos=pos;
  266.         pos=1;
  267.         files=TRUE;
  268.         filenummer=0;
  269.         pp[filenummer++]=p;
  270.  
  271.         dirs();
  272.     }
  273. }
  274.  
  275. void select_files(void)
  276. {
  277.     strcpy(line_b,filepfad);    
  278.     AddPart(line_b,pfad,80);
  279.  
  280.     p2=line_a;
  281.     p3=pp[filenummer-zeilen-2+pos];
  282.     p3++;
  283.     while(*p3!=32)
  284.     {
  285.         *p2++=*p3++;
  286.     }
  287.     *p2=0;
  288.  
  289.     AddPart(line_b,line_a,80);
  290.  
  291.     PutText("H                                                  F0");
  292.  
  293.     SelectAndDownload(line_b,FALSE);
  294.  
  295.     i=0;
  296.     bytes=0;
  297.     while(i<z->NoSelected)
  298.     {
  299.         bytes+=z->Select[i++].Size;
  300.     }
  301.     if(merkanzahl<z->NoSelected)
  302.     {
  303.         z->Select[z->NoSelected-1].CDROM=1;
  304.     }
  305.     merkanzahl=z->NoSelected;
  306.  
  307.     sprintf(line_a,"3H%d 1H%d   ",z->NoSelected,bytes/1000);
  308.     PutText(line_a);
  309.  
  310.     PutText(line_a);
  311.  
  312.     cursor(pos);
  313. }
  314.  
  315. main(int argc,char **argv)
  316. {
  317.     PreMain(argc,argv);        /*** Let it here, dute! ***/
  318.  
  319.     AddPart(indexpfad,argv[2],80);
  320.     AddPart(treepfad,argv[2],80);
  321.     AddPart(indexpfad,"index",80);
  322.     AddPart(treepfad,"tree",80);
  323.  
  324.     strcpy(readmepfad,argv[3]);
  325.     AddPart(readmepfad,"aminet/",80);
  326.  
  327.     strcpy(filepfad,argv[3]);
  328.     AddPart(filepfad,"aminet/",80);
  329.  
  330.     zeilen=z->user1.TermLength-4;
  331.  
  332.     if(z->user1.Colors==0 || z->user1.ANSI!=2)
  333.     {
  334.         PutText("n1Mindestvorraussetzung fuer CDNetn1--------------------------------n2Full Ansi + 8 Farbenn2");
  335.     }
  336.     else
  337.     {
  338.         SetDoing("CDNet");
  339.         moremode=z->user1.MoreMode;
  340.  
  341.         /* index */
  342.         fib_ptr=(struct FileInfoBlock *) AllocMem( sizeof(struct FileInfoBlock),MEMF_PUBLIC|MEMF_CLEAR);
  343.  
  344.         if(fib_ptr==NULL)
  345.         {
  346.             PutText("Not enough memory!\n");
  347.             goto hell;
  348.         }
  349.  
  350.         lock=(struct FileLock *) Lock(indexpfad,SHARED_LOCK);
  351.  
  352.         if(lock==NULL)
  353.         {
  354.             PutText("Could not lock pfiles:cdnet/.../index !\n");
  355.             /* Deallocate the memory we have allocated: */
  356.             FreeMem(fib_ptr,sizeof(struct FileInfoBlock));
  357.             goto hell;
  358.         }
  359.  
  360.         if( Examine(lock,fib_ptr)==NULL)
  361.         {
  362.             PutText("Could not examine pfiles:cdnet/.../index !\n");
  363.             FreeMem(fib_ptr,sizeof(struct FileInfoBlock));
  364.             UnLock(lock);
  365.             goto hell;
  366.         }
  367.  
  368.         laenge=fib_ptr->fib_Size;
  369.         speicher=AllocMem(laenge+1,MEMF_PUBLIC|MEMF_CLEAR);
  370.  
  371.         UnLock(lock);
  372.         FreeMem(fib_ptr,sizeof(struct FileInfoBlock));
  373.  
  374.         if (fp=fopen(indexpfad,"r"))
  375.         {
  376.             fread(speicher,laenge,1,fp);
  377.             fclose(fp);
  378.         }
  379.         else
  380.         {
  381.             PutText("Could not load pfiles:cdnet/.../index !\n");
  382.             goto hell;
  383.         }
  384.         *(speicher+laenge)=0;
  385.  
  386.         if (fp=fopen(treepfad,"r"))
  387.         {
  388.             i=0;
  389.             while(fgets(tree[i],sizeof(tree[0]),fp))
  390.             {
  391.                 tree[i][strlen(tree[i])-1]=0;
  392.                 i++;
  393.             }
  394.             fclose(fp);
  395.             anz_tree=i-1;
  396.         }
  397.         else
  398.         {
  399.             PutText("Could not load pfiles:cdnet/.../tree !\n");
  400.             goto hell2;
  401.         }
  402.  
  403.         i=0;
  404.         bytes=0;
  405.         while(i<z->NoSelected)
  406.         {
  407.             bytes+=z->Select[i++].Size;
  408.         }
  409.         merkanzahl=z->NoSelected;
  410.  
  411.         z->user1.MoreMode=0;
  412.  
  413.         dirs();
  414.  
  415.         do
  416.         {
  417.             key[0]=CNetGetKey();
  418.             switch (key[0])
  419.             {
  420.                 case '':
  421.                 {
  422.                     key[0]=CNetGetKey();
  423.                     if (key[0]==91)
  424.                     {
  425.                         key[0]=CNetGetKey();
  426.                         if (key[0]=='A')
  427.                         {
  428.                             rauf();
  429.                         }
  430.                         if (key[0]=='B')
  431.                         {
  432.                             runter();
  433.                         }
  434.                     }
  435.                     break;
  436.                 }
  437.                 case ' ':
  438.                 {
  439.                     if(files)
  440.                     {
  441.                         select_files();
  442.                     }
  443.                     break;
  444.                 }
  445.                 case 13:
  446.                 {
  447.                     if(!files)
  448.                     {
  449.                         go_files();
  450.                     }
  451.                     break;
  452.                 }
  453.                 case 'I':
  454.                 {
  455.                     if(files)
  456.                     {
  457.                         info();
  458.                     }
  459.                     break;
  460.                 }
  461.                 case 'P':
  462.                 {
  463.                     if(files)
  464.                     {
  465.                         zeilen=merkzeilen;
  466.                         pos=merkpos;
  467.                         files=FALSE;
  468.                         dirs();
  469.                     }
  470.                     break;
  471.                 }
  472.             }
  473.         }
  474.         while (key[0]!=81 && z->TimeLeft!=0);
  475.  
  476.         z->user1.MoreMode=moremode;
  477.         PutText("@0F1");
  478.     }
  479.  
  480. hell2:
  481.     FreeMem(speicher,laenge+1);
  482. hell:
  483.  
  484.     PostMain();          /*** Must be here ***/
  485. }
  486.  
  487.